import '../public.dart';

class MenuComponent extends StatelessWidget {
  const MenuComponent(
      {Key key,
      this.height = 56.0,
      this.title,
      this.onTap,
      this.hasIconArrow = true,
      this.padding,
      this.margin,
      this.leftWidgets = const [],
      this.rightWidgets = const [],
      this.titleStyle,
      this.decoration = const BoxDecoration(
          border: Border(
              top: BorderSide(
                  color: Colors.black26, width: 1, style: BorderStyle.solid)))})
      : super(key: key);

  final double height;
  final String title;
  final TextStyle titleStyle;
  final GestureTapCallback onTap;
  final bool hasIconArrow;
  final List<Widget> leftWidgets;
  final List<Widget> rightWidgets;
  final Decoration decoration;
  final EdgeInsetsGeometry padding;
  final EdgeInsetsGeometry margin;

  _getLeftWidgets() {
    List<Widget> list = [];
    list.addAll(leftWidgets);
    if (title != null) {
      list.add(Text(title,
          style: titleStyle ??
              TextStyle(
                  fontSize: 16, color: ColorUtil.rgba(255, 255, 255, 0.9))));
    }
    return list;
  }

  _getRightWidgets() {
    List<Widget> list = [];
    list.addAll(rightWidgets);
    if (hasIconArrow) {
      list.add(SVG.icon('arrow_right',
          size: 16, color: ColorUtil.rgba(255, 255, 255, 0.6)));
    }
    return list;
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
          height: height,
          decoration: decoration,
          padding: padding,
          margin: margin,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              ..._getLeftWidgets(),
              Expanded(child: SizedBox()),
              ..._getRightWidgets()
            ],
          )),
    );
  }
}
